package groupb6.shopsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import groupb6.shopsystem.pojo.entity.Return;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.sql.Time;
import java.sql.Timestamp;
import java.util.List;

@Mapper
public interface ReturnMapper extends BaseMapper<Return> {
    @Insert("INSERT INTO tb_return (order_id, status, refund, deliver_time, finish_time, allowed, reason) " +
            "VALUES (#{order_id}, 1, #{refund}, #{deliver_time}, #{finish_time}, #{allowed}, #{reason})")
    void insertReturn(Integer order_id, Float refund, Timestamp deliver_time, Timestamp finish_time, Integer allowed, String reason);
    @Update("update tb_return set allowed = 1 where id = #{returnId}")
    void returnAgree(Integer returnId);

    @Select("select * from tb_return where order_id = #{orderId}")
    List<Return> getReturnsByOrderId(Integer orderId);

    @Update("update tb_return set status = #{status} , finish_time = #{finish_time} where id = #{returnId}")
    void returnReceive(Integer returnId, Integer status, Timestamp finish_time);

    @Update("update tb_return set status = 3 where id = #{returnId}")
    void returnProduct(Integer returnId);

    @Update("update tb_return set tracking_number = #{trackingNumber} where id = #{returnId}")
    void updateTrackingNumber(Integer returnId, String trackingNumber);

    @Select("select * from tb_return where order_id = #{orderId}")
    Return getReturnByOrderId(Integer orderId);
    @Update("update tb_return set allowed = #{allowed} where id = #{id}")
    void returnAgreeById(Integer id, Integer allowed);
}
